<template>
    <div>

        <h1>病房添加</h1>
         <a href="/showbf">病房信息</a>
         <br>
        <table class="table">  
            <tbody>
             <tr>
                <td>病房号</td>
                <td>
                    <input type="text" v-model="data.houseName">
                </td>
            </tr>
            <tr>
                <td>所属科室</td>
                <td>
                   <select v-model="data.departid">
            <option value="0">请选择科室</option>
            <option v-for="e in KSxlk" :value="e.id">{{ e.departName }}</option>
        </select> 
                </td>
            </tr>
            <tr>
                <td>床位总数量</td>
                <td>
                    <input type="number" v-model="data.houseSUM">
                </td>
            </tr>
             <tr>
                <td>病房状态</td>
                <td>
                    <input v-model="data.isState" type="checkbox" checked> 选中为启用,未选中为维修
                </td>
            </tr>
            <tr>
                <td>床铺状态</td>
                <td>
                    <input v-model="data.houseState" type="radio" :value="true" name="wm" checked>未满
                    <input v-model="data.houseState" type="radio" :value="false" name="yzm">已住满
                </td>
            </tr>
            <tr>
                <td>空闲床数量</td>
                <td>
                    <input type="number" v-model="data.houseCount">
                </td>
            </tr>
             <tr> 
                <td colspan="2"> 
                    <td><input type="button" value="添加" @click="add"></td>
                </td>
            </tr>
           </tbody> 
        </table>
    </div>
</template>

<script setup lang="ts">
import {ref,onMounted} from 'vue'
import axios from 'axios'
import { useRouter } from 'vue-router'

const router=useRouter();
onMounted(()=>{ 
XLKS(); 
})

//科室下拉框
const KSxlk=ref([{
    "id": 1,
    "departName": "内科",
}])
const XLKS=()=>{
    axios.get("/api/Depart/Showxlk").then(res=>{
        KSxlk.value=res.data
    })
}


const data=ref({
  "id": 0,
  "houseName": "",
  "departid": 0,
  "houseSUM": 0,
  "isState": true,
  "houseState": true,
  "houseCount": 0,
  "houseDate": "2025-05-14T00:49:49.170Z"
})

const add =()=>{

    if(data.value.houseName=="")
{
    alert("病房名称不能为空");
    return;
}
if(data.value.houseName.length>6)
{
    alert("病房不能超过6个字符")
    return;
}
    axios.post("/api/Housenum/AddBF",data.value).then(res=>{
         if(res.data>0)
         {
            alert("病房添加成功")
             router.push({path:"/"})
         }
         else{
            alert("病房添加失败");
            return;
         }
    })
}

</script>

<style scoped>

</style>